package view;

import control.PassengerController;
import model.Passenger;

import javax.swing.*;
import java.awt.*;

public class Board {
    public static JFrame jfra;
    public static JPanel jpan1,myPanel;
    public static JLabel company, MyTripLabel, LogInLabel, ServiceLabel, VIPLabel, ModifyLabel, ContactLabel,label;
    public static ImageIcon background;

    public static PassengerController passengerController = new PassengerController();
    public static LogIn logIn = new LogIn();

    public Board(){

        jfra = new JFrame();
        //Set the background page
        background = new ImageIcon("src/view/image/background.png");    //Create a background image
        label = new JLabel(background);        //Add a background image to the label
        label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());    //Set the label to be as wide as the image
        myPanel = (JPanel) jfra.getContentPane();        //Set myPanel to the Content panel
        myPanel.setOpaque(false);                    //Make myPanel invisible
        myPanel.setLayout(new FlowLayout());        //Set myPanel to a flowing layout
        jfra.getLayeredPane().setLayout(null);        //Leave the layout of the layered panel blank

//        create bar
        jpan1 = new JPanel();
        company = new JLabel("          Check-In Kiosk                    ", JLabel.LEFT);
        Font fnt = new Font("Serief", Font.BOLD, 40);// Setting the size and style of the font.
        company.setFont(fnt);

        LogInLabel = new JLabel("LogIn          ", JLabel.RIGHT);
        LogInLabel.setBackground(Color.YELLOW);
        MyTripLabel = new JLabel("MyTrip          ", JLabel.RIGHT);
        ServiceLabel = new JLabel("Service         ", JLabel.RIGHT);
        VIPLabel = new JLabel("VIP         ", JLabel.RIGHT);
        ModifyLabel = new JLabel("Board         ", JLabel.RIGHT);
        ContactLabel = new JLabel("Contact           ", JLabel.RIGHT);
        company.setForeground(Color.blue);
        jpan1.add(company);
        jpan1.add(LogInLabel);
        jpan1.add(MyTripLabel);
        jpan1.add(ServiceLabel);
        jpan1.add(VIPLabel);
        jpan1.add(ModifyLabel);
        jpan1.add(ContactLabel);
        jpan1.setVisible(true);
//get the passenger information
        int index=0;
        Passenger passenger = passengerController.queryByBookNumber(logIn.bookNumber);
        for (int i = 0; i < passenger.getPlaneNum().length; i++) {
            if(passenger.getPlaneNum()[i].equals(LogIn.currentPlaneNum)){
                index = i;
            }
        }
        System.out.println(passenger);
        System.out.println();
//show the passenger information
        JPanel jpanShow=new JPanel(new BorderLayout());
        jpanShow.setPreferredSize(new Dimension(400,400));
        JLabel label0=new JLabel("Printing",JLabel.CENTER);
        Font fnt0 = new Font("Serief", Font.BOLD, 28);// Setting the size and style of the font.
        label0.setFont(fnt0);
        JPanel jpan0=new JPanel();
        jpan0.setLayout(new GridLayout(5, 1));
        JLabel label1=new JLabel("Boarding Pass ");
        Font fnt1 = new Font("Serief", Font.ITALIC, 18);// Setting the size and style of the font.
        label1.setFont(fnt1);
        JLabel label2=new JLabel("Dear "+passenger.getSurname());
        Font fnt2 = new Font("Serief", Font.BOLD, 18);// Setting the size and style of the font.
        label2.setFont(fnt2);
        JLabel label4=new JLabel("The following is your boarding information: ");
        JPanel jpanm=new JPanel();
        jpanm.setLayout(new GridLayout(3, 1));
        JLabel label3=new JLabel("Your booking number is "+passenger.getBookNumber()+".");
        JLabel label8=new JLabel("delicious "+passenger.getFood()[index]+" food.");
        JLabel label6=new JLabel("You have chosen the "+passenger.getRow()[index]+"th row and the "+passenger.getCol()[index]+"th column seat &");
        jpanm.add(label3);
        jpanm.add(label6);
        jpanm.add(label8);
        jpanm.setVisible(true);
        JLabel label5=new JLabel("Hope you have a good journey!");
        Font fnt5 = new Font("Serief", Font.BOLD, 18);// Setting the size and style of the font.
        label5.setFont(fnt5);
        jpanShow.add(label0,BorderLayout.NORTH);
        jpan0.add(label1);
        jpan0.add(label2);
        jpan0.add(label4);
        jpan0.add(jpanm);
        jpan0.add(label5);
        jpanShow.add(jpan0,BorderLayout.CENTER);
        
        //set myPanel
        myPanel.add(jpan1);
        myPanel.add(jpanShow);
        jfra.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));        //Add labels to the bottom layer of the layered panel
        //Set interface properties
        jfra.setBounds(300, 300, background.getIconWidth(), background.getIconHeight());
        jfra.setVisible(true);
        jfra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    }
}
